from db.aiomysql_connector import AioMysqlClient
from header.digit_twin_header import DigitTwinHeader
from logger_config import logger
from services.cache_service import CacheUtils


class AlarmService:
    table = 'Alarm'

    def __init__(self):
        self.sql_client: AioMysqlClient = CacheUtils.get('aiomysql_pool')

    async def alarm_data(self):
        try:
            sql = f"select data100,data101,data102,data103,data104 from {self.table}"
            alarm_data = await self.sql_client.fetch_all(sql)
        except Exception as e:
            alarm_data = []
            logger.error(e)
        return_data = {
            'header': DigitTwinHeader.alarm_header,
            'data': alarm_data,
        }
        return return_data
